package com.mytools.test;

import cn.hutool.json.JSONUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.LongSerializationPolicy;
import com.mytools.util.ImgMatchUtil;
import com.mytools.util.MyHttpsUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class MyTest2 {

    public static void main(String[] args) throws Exception {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setLongSerializationPolicy(LongSerializationPolicy.STRING);
        Gson gson = gsonBuilder.create();

        Map skuListMap = new HashMap();

        String data = MyHttpsUtils.requestGet("https://item.jd.com/43494072820.html", null);
        Document doc = Jsoup.parse(data);
//      System.out.println("name:"+doc.getElementsByAttributeValue("class","name").first().text());
        List<String> list2 = ImgMatchUtil.getMatchList(data, "mainSkuId:'.*', ", true);
        String str=list2.get(0);
        System.out.println(str);
        System.out.println(str.substring(11,str.lastIndexOf("',")));


//        List<String> list2 = ImgMatchUtil.getMatchList(data, "colorSize:.*\\}\\]", true);
//        String goodsString=list2.get(0);
//        list2 = ImgMatchUtil.getMatchList(goodsString, "\\[\\{.*\\}\\]", true);
//        List info = JSONUtil.parseArray(list2.get(0));
//        for (Object o : info) {
//            Map omap = (Map) o;
//            omap.entrySet();
//            String name="";
//            for(Object key:omap.keySet()){//keySet获取map集合key的集合  然后在遍历key即可
//                String value = omap.get(key).toString();//
//                if("skuId".equals(key)){
//                    continue;
//                }
//                name= name+key+":"+value +"XXX";
//            }
//            omap.put("name",name);
//            skuListMap.put( omap.get("skuId"),omap);
////            System.out.println(skuListMap);
//        }
    }
}
